package com.lyl.dangdang.controller;


import com.lyl.dangdang.pojo.Result;
import com.lyl.dangdang.pojo.po.Address;
import com.lyl.dangdang.service.IAddressService;
import com.lyl.dangdang.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liyunlong
 * @since 2024-06-09
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @PostMapping("/addAddress")
    public Result addAddress(@RequestBody Address address) {
        Integer currentUser = ThreadLocalUtil.getCurrentUser();
        address.setUserId(currentUser);
         addressService.saveOrUpdate(address);
         return Result.success();
    }

    @DeleteMapping("/deleteAddress/{addressId}")
    public Result deleteAddress(@PathVariable("addressId") Integer addressId) {
        return addressService.deleteAddress(addressId);
    }
    @GetMapping("/getUserAddressByAddressId/{addressId}")
    public Result getUserAddressByAddressId(@PathVariable("addressId") Integer addressId) {
        return addressService.getUserAddressByAddressId(addressId);
    }

}
